'''
Created on Jun 9, 2012

@author: Timothy A. Mann
'''

import kryptos.freq
import kryptos.text
import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    text = "This is a test string. The purpose of this test is to test the n-gram extraction functions.".lower()
    text = kryptos.text.extractLetters(text)
    
    ngramMap = kryptos.freq.ngram_counts_map(text, 4, minCount=2)
    sNgramMap = kryptos.freq.sort_map_by_value(ngramMap)
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    left = np.arange(len(sNgramMap))
    width = 0.5
    height = []
    labels = []
    for (k,v) in sNgramMap:
        labels.append(k)
        height.append(v)
    height = np.array(height)
    plt.bar(left, height, width)
    plt.xlabel('N-grams')
    plt.ylabel('# Occurrences')
    plt.xticks(left + width/2, labels)
    fig.autofmt_xdate()
    
    plt.show()